package com.zkc.stume.controller;

import com.zkc.stume.bean.Dat;
import com.zkc.stume.service.DatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(description ="CURD增删改查")
public class CurdController {
    @Autowired
    private DatService datService;



    @GetMapping("/")
    @ApiOperation(value = "访问首页")
    public String curd(Model model){
        model.addAttribute("stu","学习");
        return "curd";
    }



    @GetMapping("/all")
    @ApiOperation(value = "CURD 全查")
    @ResponseBody
    public List<Dat> c(){
          List<Dat> datss= datService.getAll();
          return datss;
    }

    @GetMapping(value = "/dan/{id}")
    @ApiOperation(value = "CURD 单个查询")
    @ResponseBody
    /*@PathVariable从路径获取id*/
    public Dat dan(@ApiParam("单个查询的id") @PathVariable("id")Integer id){
        Dat listsss= datService.datdan(id);
        return listsss;
    }

    @PutMapping("/xiugai/{mid}")
    @ApiOperation(value = "CURD 修改")
    @ResponseBody
    public Integer xiugai(@ApiParam("要修改的josn数据") @RequestBody Dat dat){
        Integer x= datService.xiugai(dat);
        return x;
    }

    @PostMapping("/zenjia")
    @ApiOperation(value = "CURD 添加")
    @ResponseBody
    public Integer zenjia(@ApiParam("添加的json数据") @RequestBody Dat dat){
        Integer z= datService.zengjia(dat);
        return z;
    }

    @DeleteMapping("/shan/{sid}")
    @ResponseBody
    @ApiOperation("CURD 删除")
    public Integer shanchu(@ApiParam("要删除的数据id") @PathVariable("sid") Integer id){
         Integer s= datService.shanchu(id);
          return s;
    }




}
